<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no" />
		<title>首页</title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/ffxiang.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../css/qutoutiao.css" />
		<style>
			 #fx-header {
				margin-bottom: 0px;
				padding-bottom: 36px;
				border-bottom: 1px solid #E2E2E2;
			}
			#fx-header .aui-btn p{
				color:#fff;
				font-weight: bold;
			}
			@-webkit-keyframes rotation{
				from {-webkit-transform: rotate(0deg);}
				to {-webkit-transform: rotate(360deg);}
			}
			.Rotation{
				-webkit-transform: rotate(360deg);
				animation: rotation 1s linear infinite;
				-moz-animation: rotation 1s linear infinite;
				-webkit-animation: rotation 1s linear infinite;
				-o-animation: rotation 1s linear infinite;
			}

		</style>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav" id="fx-header">
			<!--<div class="fx-header-logo">
				<a class="aui-pull-left"> <span class="aui-iconfont aui-icon-left"></span> </a>
				<div class="aui-title" style="left:5rem; right: 0.2rem;" tapmode onclick="search()">
					<div class="aui-searchbar" id="search">
						<div class="aui-searchbar-input aui-border-radius">
							<i class="aui-iconfont aui-icon-search"></i>
							<input type="search" placeholder="搜索关键词" id="search-input" readonly>
						</div>
					</div>
				</div>
			</div>-->
			<!--时后期开发暂-->
			<!--<div class="fx-right-jia" tapmode onclick="_url('jiatypeid_win','','1')">
			<i class="aui-iconfont aui-icon-plus"></i>
			</div>-->
			<!--2018年7月9日 17:38:56  修改-->
			<a class="aui-pull-left aui-btn" tapmode onclick="_url({url:'yaoqing/renwu',title:'任务系统'},'',true)">
	            <div class="user2" style="display: block"><img src="../image/qutoutiao/24.png" /></div>
	        </a>
	        <div class="aui-title" style="left:2rem; right: 4rem;" tapmode onclick="search()">
	            <div class="aui-searchbar" id="search">
						<div class="aui-searchbar-input aui-border-radius">
							<i class="aui-iconfont aui-icon-search"></i>
							<input type="search" placeholder="搜索你感兴趣的内容" id="search-input" readonly>
						</div>
					</div>
	        </div>
	        <a class="aui-pull-right aui-btn header-time" tapmode onclick="baoxiangAjax()">
	        	<div class="header-lingqu">领取</div>
	            <div class="header-yuan"><em><img src="../image/qutoutiao/header-jinbi.png" /></em></div>
	        </a>
		</header>
		<footer class="aui-bar aui-bar-tab" id="fx-footer">
			<div class="aui-bar-tab-item aui-active " tapmode onclick="shuaxin()">
				<img class="aui-img-object Rotation" src="../image/shuaxin_2.png" />
				<div class="aui-bar-tab-label">
					刷新
				</div>
			</div>
			<div class="aui-bar-tab-item" tapmode onclick="_index_win('video_win')" >
				<img class="aui-img-object" src="../image/w2.png" />
				<div class="aui-bar-tab-label">
					视频
				</div>
			</div>
			<div class="aui-bar-tab-item" tapmode onclick="_index_win('weitoutiao_win')">
				<img class="aui-img-object" src="../image/w3.png" />
				<div class="aui-bar-tab-label">
					微头条
				</div>
			</div>
			<!--<div class="aui-bar-tab-item" tapmode onclick="_index_win('xiaoshipin_win')">
				<img class="aui-img-object" src="../image/w5.png" />
				<div class="aui-bar-tab-label">
					小视频
				</div>
			</div>-->
			<!--<div class="aui-bar-tab-item" tapmode onclick="_index_win('renwu_win')" >
				<img class="aui-img-object" src="../image/qutoutiao/w6.png" />
				<div class="aui-bar-tab-label">
					任务
				</div>
			</div>-->
			<div class="aui-bar-tab-item" tapmode onclick="_index_win('member_wins')">
				<img class="aui-img-object" src="../image/w4.png" />
				<div class="aui-bar-tab-label">
					我的
				</div>
			</div>
		</footer>

	</body>

	<script type="text/javascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/ffxiang.js"></script>
	<script type="text/javascript">
		var body_h;
		var headerPos;
		var typeid;
		var NVNavigationBar;
		var retindex=0
		// 分类栏目模块
		var heiff = 35;
		var activity
		var likaitime=60000;//1000=1秒
		var time;
		var mnPopups;
		var config;
		var typeid_keyback=false
		//输入35会显示右侧点击
		apiready = function() {
			//_url({url:'yaoqing/tixian',title:'提现列表'},'',true)
 			mnPopups = api.require('MNPopups');
			NVNavigationBar = api.require('NVNavigationBar');
			if(!$api.getStorage('yindaotu')){
				_openFrame('yindaotu')
			}else{
				dat()
			}
			// 2018年8月27日 23:45:54
			// 增加宝箱
			baoxiagnInfo();
			_daily({name:'money_login'})
		//	 _url({index:1},'member/ScLs_win',true)
			// 回到屏幕
			api.addEventListener({
				name : 'viewappear'
			}, function(ret, err) {
				userImg()
				_heibai(1);
				api.setFullScreen({
				    fullScreen: false
				});
				baoxiagnInfo(1)
				// 2018年3月10日 22:09:31 增加
				// 每日登录奖励
				_daily({name:'money_login'})
				// 每日阅读5篇奖励
				//_daily({name:'money_news'})
				typeid_keyback=false
			});
			_heibai(1);
			api.addEventListener({
				name : 'smartupdatefinish'
			}, function(ret, err) {
				alert('APP自动修复完成，需要重启APP才能生效');
				api.rebootApp();
			});
			// 监听夜间
			api.addEventListener({
				name : 'yejian'
			}, function(ret, err) {
				if (ret) {
					_yejians();
				}
			});
			_gengxin()
			//应用进入后台事件
			api.addEventListener({
				name : 'pause'
			}, function(ret, err) {
				time = Date.parse(new Date());
				time = time + likaitime
				$api.setStorage('time', time);
			});
			// 应用从后台回到前台事件
			api.addEventListener({
				name : 'resume'
			}, function(ret, err) {
				time = Date.parse(new Date());
				if ($api.getStorage('time')) {
					if (time > $api.getStorage('time')) {
						ad()
					}
				}
			});
		}
		function view() {
			header = $api.byId('fx-header');
			$api.fixStatusBar(header);
			headerPos = $api.offset(header);
			body_h = $api.offset($api.dom('body')).h;
			$api.fixTabBar($api.byId('fx-footer'))
			footerh = $api.offset($api.byId('fx-footer')).h;
			footerh = footerh - 5

			var ret=$api.getStorage('typeid');
				// 获取上架显示
				//_shangjia()
				// 2018年3月1日 13:35:28 增加获取配置
				_config();
				// 配置结束
				if (ret) {
					api.closeFrame({
						name : 'error'
					});
					typeid = ret.typeid// 获取分类json
					// 读取栏目分类模块
					type_Info(ret.data,typeid)
				} else {
					api.openFrame({
						name : 'error',
						url : html_win + 'error.html',
						bounces : false,
						rect : {
							x : 0,
							y : 0,
							w : 'auto',
							h : 'auto'
						},
						useWKWebView : true,
						historyGestureEnabled : true,
						vScrollBarEnabled : false,
						hScrollBarEnabled : false,
					})
				}
		 		userImg()
		}
		function openFrameGroup(frames) {
			api.openFrameGroup({
				name : 'ffxiang_frm',
				scrollEnabled : true,
				rect : {
					x : 0,
					y : headerPos.h + heiff - 35,
					w : 'auto',
					h : body_h - headerPos.h - heiff + 30 - footerh,
				},
				index : 1,
				frames : frames,
				preload : 0,	// 预加载的 frame 个数，默认加载当前页后面一个
			}, function(ret, err) {
				// 当滑动时，设置栏目选中颜色
				NVNavigationBar.setSelected({
					id : 'first',
					index : ret.index,
					selected : true
				});
				retindex=ret.index
			});
		}

		// 点击分类栏目时，设置 frame 组当前可见 frame
		function randomSwitchBtn(index) {
			if(index==retindex){
				shuaxin()
				return;
			}
			api.setFrameGroupIndex({
				name : 'ffxiang_frm',
				index : index,
				scroll : true,	//是否平滑滚动至目标窗口，即是否带有动画
				//reload:true,	// 刷新
			});
		}

		// 读取会员信息
		function _user() {
			api.sendEvent({
				name : 'ffxiangUser',
				extra : {
					user : $api.getStorage('user'),
				}
			});
		}

		// 搜索
		function search() {
			api.openWin({
				name : 'search_win',
				url : html_win+'search_win.html',
				slidBackEnabled : false,
				animation : {
					type : "fade", //动画类型（详见动画类型常量）
					subType : "from_right", //动画子类型（详见动画子类型常量）
					duration : 300
				},
				pageParam : {
					qian : 1,
					fan : 0
				}
			});
		}

		// 打开提示
		function UILoadings() {
			var loading = new Array;
			for (var i = 0; i < 39; i++) {
				loading[i] = {
					frame : 'widget://html/image/loading/' + (i + 1) + '.fw.png'
				};
			}
			UILoading = api.require('UILoading');
			UILoading.keyFrame({
				rect : {
					w : api.winWidth,
					h : api.winHeight
				},
				styles : {
					bg : '#fff',
					corner : 0,
					interval : 39,
					frame : {
						w : 247,
						h : 271
					}
				},
				content : loading,
				mask : '#fff'
			}, function(ret) {
			});
		}

		// 关闭提示
		function UILoadingClose() {
			UILoading.closeKeyFrame();
		}

		// 夜间
		function yejian() {
			api.sendEvent({
				name : 'yejian',
				extra : {
					yejian : '1',
				}
			});
		}
		// 首次获取城市定位
		function cityAjax(){
			var baiduLocation = api.require('baiduLocation');
			baiduLocation.startLocation({
			}, function(ret, err) {
			    if (ret.status) {
			        var latitude=ret.latitude
			        var longitude=ret.longitude

			        if(latitude && longitude){
			        	_ajax('api/index/cityDingwei',function(ret,err){
			        		if(ret){
			        			if(ret.ret){
			        			//	alert('latitude:'+latitude+"\r\nlongitude:"+longitude+"\r\nret:"+JSON.stringify(ret.ret))
				        			ret=ret.ret
				        			$api.setStorage('city', encodeURIComponent(encodeURIComponent(ret)));
				        			updateItem(ret)
			        			}
			        		}
			        	},{latitude:latitude,longitude:longitude})
			        }
			    }
			});
		}
		// 更新栏目内容
		function updateItem(ret){
			ret = ret ? ret : decodeURIComponent(decodeURIComponent($api.getStorage('city')));
			if(!ret || ret==""){
				return;
			}
			if(ret == 'undefined'){
				ret='本地'
			}
			var w=typeidstrlen(ret);
			NVNavigationBar.updateItem({
			    id: 'first',
			    index: 2,
			   	item:{
			   		title:ret,
			   		bgSelected:'#fff',
			   		bg:'#fff',
			   		size:{
			   			w:w,
			   			h:heiff
			   		}
			   	}
			});

		}
		// 更新选择城市新闻
		function cityNews(){

			updateItem()
			api.execScript({
				frameName:'frame_2',
				script: 'cityNews()'
			});

			NVNavigationBar.setSelected({
				id : 'first',
				index : 2,
				selected : true
			});
		}
		// 分类取出长度
		function typeidstrlen(str){
			if(str.length < 3){
				return 50;
			}
		    var len = 0;
		    for (var i=0; i<str.length; i++) {
		     var c = str.charCodeAt(i);
		    //单字节加1
		     if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
		       len++;
		     }
		     else {
		      len+=3;
		     }
		    }
		    return Math.ceil(len*8.3333333);
		}
		// 广告
		function ad(){
			if($api.getStorage('ad') && $api.getStorage('adimage')){
				api.openWin({
					name : 'ad',
					url : html_win+'ad.html',
					reload:true,
					bounces:false,
					animation:{
						type:"none",                //动画类型（详见动画类型常量）
						subType:"from_bottom",       //动画子类型（详见动画子类型常量）
						duration:300
					},
				});
			}else{
				adAjax()
			}
		}
		function adAjax(){
			_ajax('api/article/ad',function(ret,err){
				if(ret){
					if(ret.ret){
					//	console.log(JSON.stringify(ret.ret));
						$api.setStorage('ad', ret.ret);
					//	console.log(fx_cdn+ret.ret.data.image)
						api.imageCache({
							url : fx_cdn+ret.ret.data.image,
							thumbnail:false,
						}, function(ret, err) {
							if (ret) {
								if (ret.status) {
								//	console.log(ret.url);
									$api.setStorage('adimage', ret.url);
								}
							}
						});
						return;
					}
				}
				$api.rmStorage('ad')
				$api.rmStorage('adimage')
			})
		}
		//  获取配置
		function _config(){
			_ajax('api/article/config',function(ret,err){
				if(ret){
				 //	console.log(JSON.stringify(ret.config.shengmis));
					$api.setStorage('config', ret);
					config = ret;
				//	_index_win('member_win')
				}else{
					alert(JSON.stringify(err));
				}
			})
		}
		// 获取上架记录
		function _shangjia(){
			_ajax('api/index/pingguoApp',function(ret,err){
				if(ret){
					$api.setStorage('app', '1');
				}else{
					$api.rmStorage('app')
				}
			})
		}
		// 更新用户信息
		function _userInfo(){
			//console.log('用户更新成功拉！')
			_user=$api.getStorage('user')
			if(!_user){
				return;
			}
			_ajax('api/member/info', function(ret, err) {
				if (ret) {
					$api.setStorage('user', ret.ret);
				}
			})
		}
		function dat(){
			UILoadings()
			view();
			ad()
		}
		// 显示登录头像
		function userImg(){
			return
			var user=$api.getStorage('user');
			if(user){
				$api.css($api.dom('.user1'),"display: block");
				$api.css($api.dom('.user2'),"display: none");
				$api.attr($api.dom('.sx-user-img'),"src",user.img);
			}else{
				$api.css($api.dom('.user1'),"display: none");
				$api.css($api.dom('.user2'),"display: block");
			}
		}
		// 打开菜单
		function right(){
			var y=$api.offset($api.byId('fx-header')).h-40;
			mnPopups.open({
			    rect: {
			        w: 130,
			        h: 135
			    },
			    position: {
			        x: api.winWidth - 25,
			        y: y
			    },
			    styles: {
			        mask: 'rgba(0,0,0,0)',
			        bg: '#565656',
			        corner:5,
			        cell: {
			            bg: {
			                normal: '#565656',
			                highlight: '#404040'
			            },
			            h: 45,
			            title: {
			                marginL: 45,
			                color: '#fff',
			                size: 14,
			            },
			            icon: {
			                marginL: 10,
			                w: 20,
			                h: 20,
			                corner: 2
			            },
			            separateLine: {              //（可选项）JSON 类型；分割线的样式设置
				            width: 1,                //（可选项）数字类型；分割线的粗细，默认为1
				            marginLR: 10,              //（可选项）数字类型；分割线距离左右的间距，默认为0
				            bg: '#838383',            //（可选项）字符类型；分割线的背景颜色，支持rgb、rgba、#；默认：#C0C0C0
				            hideLastSeparateLine: true //(可选项)布尔类型；是否隐藏最后一条分割线，默认false
				        },
			        },
			        pointer: {
			            size: 7,
			            xPercent: 90,
			            yPercent: 0,
			            orientation: 'downward'
			        }
			    },
			    datas: [{
			        title: '发图文',
			        icon: _image+'sx-index-right-1.png'
			    }, {
			        title: '拍小视频',
			        icon: _image+'sx-index-right-2.png'
			    }, {
			        title: '上传视频',
			        icon: _image+'sx-index-right-3.png'
			    } ],
//			    , {
//			        title: '提问',
//			        icon: '../image/sx-index-right-4.png'
//			    }
			    animation: true
			}, function(ret) {
			    if(ret.eventType=="click"){
			    	var index=ret.index;
			    	if(index==0){
			    		_url({type:'text'},'member/weitoutiaoAdd_win',true)
			    	}else if(index==1){
			    		_svideo()
			    	}else if(index==2){
			    		_url({type:'video'},'member/weitoutiaoAdd_win',true)
			    	}
			    }
			});
		}
		// 刷新
		function shuaxin(){
			$api.addCls($api.dom('.aui-active img'),'Rotation')
			api.execScript({
				frameName:'frame_'+retindex,
				script: 'shuaxin()'
			});
		}
		// 打开频道
		function typeid_add(y) {
			return
			api.openFrame({
				name : 'typeid_add',
				url : html_win + 'typeid_add.html',
				bounces : false,
				rect : {
					x : api.winWidth - 80,
					y : headerPos.h  - heiff-1,
					w :80,
					h : heiff-1,
				},
				bgColor : 'rgba(0,0,0,0)',
				animation:{
					type:"none",                //动画类型（详见动画类型常量）
				    subType:"from_right",       //动画子类型（详见动画子类型常量）
				    duration:300
				},
				pageParam:{
					h:headerPos.h
				}
			})
		}

		var times=0
		function addTiem(te){
			times=te;
			countDown()
		}
		// 判断是否显示倒计时和宝箱
		function baoxiagnInfo(id){
			var user=$api.getStorage('user');
			if(!user){
				return
			}
			_ajax('api/yaoqing/renwu',function(ret,err){

				if(ret){
					if(ret.baoxiang){
						clearInterval(timer);
						times=ret.baoxiang
						countDown();
					}
				}
			})
		}
		// 切换宝箱按钮
		// id 0倒计时 1开启宝箱
		function baoxiangBtn(id){
			var lingqu=$('.header-lingqu');
			var yuan=$('.header-yuan em');
			if(id==1){
				lingqu.text('领取')
				yuan.html('<img src="../image/qutoutiao/header-jinbi.png" />')
			}else{
				yuan.html('<img src="../image/header-time.png" />')
				times=config.renwu.baoxiang*60;
				lingqu.text(miaotime(times))
				countDown()
			}
		}
		var timer=null;
		//带天数的倒计时
		function countDown(){
		  timer=setInterval(function(){
		  	 times--;
		    var day=0,
		      hour=0,
		      minute=0,
		      second=0;//时间默认值
		    if(times > 0){
		      day = Math.floor(times / (60 * 60 * 24));
		      hour = Math.floor(times / (60 * 60)) - (day * 24);
		      minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60);
		      second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
		    }
		    if (day <= 9) day = '0' + day;
		    if (hour <= 9) hour = '0' + hour;
		    if (minute <= 9) minute = '0' + minute;
		    if (second <= 9) second = '0' + second;
		    //
		 //   console.log(times);
		    $api.text($api.dom('.header-lingqu'),minute+":"+second)

		    if(times<0){
		      clearInterval(timer);
		      baoxiangBtn(1)
		    }
		  },1000);
		}
		// 根据毫秒时间转换时间格式
		function miaotime(t){
			day = Math.floor(t / (60 * 60 * 24));
		      hour = Math.floor(t / (60 * 60)) - (day * 24);
		      minute = Math.floor(t / 60) - (day * 24 * 60) - (hour * 60);
		      second = Math.floor(t) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
		      if (day <= 9) day = '0' + day;
		    if (hour <= 9) hour = '0' + hour;
		    if (minute <= 9) minute = '0' + minute;
		    if (second <= 9) second = '0' + second;
			return minute+":"+second
		}
		// 打开宝箱奖励
		function baoxiangAjax(){
			var user=$api.getStorage('user');
			if(!user){
				_login();
				return
			}
			if(times>0){
		      return
		    }
			_loading('领取中。。。')
			_ajax('api/yaoqing/baoxiangAjax',function(ret,err){
				_loadingCloes();
				if(ret){
					if(ret.ret){
						baoxiangBtn(0);
						fenxiang_text(ret.ret)
					}else{
						_msg(ret.err)
					}
				}
			})
		}
		function fenxiang_text(text){
			api.openFrame({
				name : 'baoxiang_win',
				url : html_win+'baoxiang_win.html',
				animation : {
					type : "fade", //动画类型（详见动画类型常量）
					subType : "from_bottom", //动画子类型（详见动画子类型常量）
					duration : 300
				},
				rect : {
					x : 0,
					y : 0,
					w : 'auto',
					h : 'auto'
				},
				bgColor : 'rgba(0,0,0,0)',
				pageParam : {
					text : text
				},
				useWKWebView : true,
			});
		}
		// 打开频道
		function typeid_add(y) {
			api.openFrame({
				name : 'typeid_add',
				url : html_win + 'typeid_add.html',
				bounces : false,
				rect : {
					x : api.winWidth - 80,
					y : headerPos.h  - heiff-1,
					w :80,
					h : heiff-1,
				},
				bgColor : 'rgba(0,0,0,0)',
				animation:{
					type:"none",                //动画类型（详见动画类型常量）
				    subType:"from_right",       //动画子类型（详见动画子类型常量）
				    duration:300
				},
				pageParam:{
					h:headerPos.h
				}
			})
		}
		// 加载分类
		function type_Info(a,typeid){
			NVNavigationBar.open({
				rect : {
					x : 0,
					y : headerPos.h - 36,
					w : api.frameWidth,
					h : heiff
				},
				styles : {
					orientation : 'horizontal',
					bg : '#fff',
					bgAlpha : 1,
					font : {
						size : 17,
						sizeSelected : 18,
						color : '#222222',
						colorSelected : '#D43D3D',
						alpha : 1
					},
					itemSize : {
						w : 50,
						h : heiff
					},
					bounces:true,
				},
				items : a,
				selectedIndex : 0,
				fixedOn : api.frameName,
				id : 'first',

			}, function(ret, err) {
				if (ret.eventType == 'click') {
					randomSwitchBtn(ret.index)
				}
				if(ret.eventType=='show'){
					typeid_add(headerPos.h - 36)
					UILoadingClose()
					if($api.getStorage('city')){
						updateItem()
					}else{
						cityAjax()
					}
				}
			});
			api.closeFrameGroup({
			    name: 'ffxiang_frm'
			});
			// 打开页面
			var frames = [];
			for (var i = 0; i < typeid.length; i++) {
				var frame = {};
				frame.name = 'frame_' + i;
				frame.url = html_win + 'ffxiang_frm.html';
				frame.pageParam = {
					id : typeid[i],
				};
				frames.push(frame);
				frames.useWKWebView = true;
				frames.historyGestureEnabled = true;
			}

			openFrameGroup(frames);
			api.parseTapmode();
		}
		// 更新栏目分类
		function typeDataAdd(){
			var a = $api.getStorage('typeid_get');
		//	console.log(JSON.stringify(a))
			type_Info(a.data,a.typeid)
			return;

//			alert(1)

			NVNavigationBar.update({
			    id: 'first',
			    items:a
			}, function(ret) {
			    alert(JSON.stringify(ret));
			});
		}
		// 判断程序退出
		function keyback(){
			if(!typeid_keyback){
				_close()
			}else{
				api.closeFrame({name:'typeid_add_info'});
				typeid_keyback_false();
			}
		}
		function typeid_keyback_true(){
			typeid_keyback=true;
		}
		function typeid_keyback_false(){
			typeid_keyback=false;
		}

	</script>

</html>


